<template>
  <div class="app-container">
    <div class="head-container">
      <!-- 搜索 -->
      <div>
        <el-select v-model="query.version" clearable class="filter-item" style="width: 180px;" placeholder="调查版本" @change="toQuery">
          <el-option v-for="item in versionList" :key="item.version" :label="item.remark" :value="item.version"/>
        </el-select>
        <el-button class="filter-item" size="mini" type="warning" icon="el-icon-search" @click.stop="toQuery">搜索</el-button>
      </div>
      <e-content ref="content"/>
    </div>
    <!--表格渲染-->
    <el-table id="orderList" ref="dataTable" :data="data" size="small" stripe style="width: 100%;">
      <el-table-column prop width="100" align="center" label="序号">
        <template slot-scope="scope">
          {{ scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column prop="userName" label="用户名" align="left" min-width="100"/>
      <el-table-column prop="phone" label="联系电话" align="center"/>
      <el-table-column prop="addr" label="地址" align="center"/>
      <el-table-column prop="suggest" label="用户建议" align="center" min-width="200" />
      <el-table-column label="操作" width="200px" align="center">
        <template slot-scope="scope">
          <el-button size="mini" type="primary" icon="el-icon-s-opportunity" @click.stop="getContent(scope.row.userId)">用户问卷明细</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--分页组件-->
    <!--<el-pagination :total="total" :page-size="pageSize" :page-sizes="sizes" :current-page="pageIndex" style="margin-top: 8px;" layout="total, sizes, prev, pager, next, jumper" @size-change="sizeChange" @current-change="pageChange" />-->
  </div>
</template>

<script>
import initData from '@/mixins/initData'
import eContent from './module/content'
import { formatDate, trim } from '@/utils/index'
import { getVersionList, exportItem, getUserDetail } from '@/api/backApi'

export default {
  components: { eContent },
  mixins: [initData],
  data() {
    return {
      sup_this: this,
      versionList: [],
      query: {},
      estateList: []
    }
  },
  created() {
    this.$nextTick(() => {
      this.getVersionList()
      this.init()
    })
  },
  methods: {
    formatDate,
    trim,
    beforeInit() {
      const query = this.query
      this.url = '/question/statistics/suggest'
      this.params = {
        version: query.version
      }
      return true
    },
    toQuery() {
      this.init()
    },
    getVersionList() {
      getVersionList().then((res) => {
        this.versionList = res.data
        // this.query.version = res.data[0].version
      })
    },
    exportTable(questionTplId) {
      const query = this.query
      exportItem({
        questionTplId: questionTplId,
        version: query.version
      }).then((res) => {
        const link = document.createElement('a')
        const blob = new Blob([res], { type: 'application/vnd.ms-excel' })
        link.style.display = 'none'
        link.href = URL.createObjectURL(blob)

        link.download = '订单' // 下载的文件名
        document.body.appendChild(link)
        link.click()
        document.body.removeChild(link)
      })
    },
    getContent(id) {
      const _this = this.$refs.content
      const params = { userId: id }
      getUserDetail(params).then(res => {
        _this.data = res.data
        _this.dialog = true
      })
    }
  }
}
</script>

<style>
</style>
